//
//  ChooseProjectViewCell.m
//  IpadR
//
//  Created by mac on 2017/6/3.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ChooseProjectViewCell.h"

@interface ChooseProjectViewCell()

@end

@implementation ChooseProjectViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//        [self SetUpUI];
        
    }
    self.selectionStyle =UITableViewCellSelectionStyleNone;
    return self;
}




- (void)configUIWithArr:(NSMutableArray *)array andNumber:(NSInteger)section{
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    //cell 加阴影
    self.layer.shadowOpacity = 0.5;// 阴影透明度
    
    self.layer.shadowColor = [UIColor grayColor].CGColor;// 阴影的颜色
    
    self.layer.shadowRadius = 3;// 阴影扩散的范围控制
    
    self.layer.shadowOffset  = CGSizeMake(1, 1);// 阴影的范围
    

     // CELL 里面的控件加阴影
    self.contentView.layer.shadowOpacity = 0.5;// 阴影透明度
    
    self.contentView.layer.shadowColor = [UIColor grayColor].CGColor;// 阴影的颜色
    
    self.contentView.layer.shadowRadius = 3;// 阴影扩散的范围控制
    
    self.contentView.layer.shadowOffset  = CGSizeMake(1, 1);// 阴影的范围
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = [UIFont systemFontOfSize:16*AutoScaleHorizontal];
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.text = @"添加第一组测试项目";
    [self.titleLabel setTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(30*AutoScaleHorizontal);
        make.top.mas_equalTo(self.contentView.mas_top).with.offset(20*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(200*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.deleteGrowpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.deleteGrowpBtn.backgroundColor = UIColorFromRGB(49, 183, 188);
    [self.deleteGrowpBtn setTitle:@"删除该组" forState:UIControlStateNormal];
    [self.deleteGrowpBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.deleteGrowpBtn addTarget:self action:@selector(godelete) forControlEvents:UIControlEventTouchUpInside];
    self.deleteGrowpBtn.titleLabel.font = [UIFont systemFontOfSize:14*AutoScaleHorizontal];
    [self.contentView addSubview:self.deleteGrowpBtn];
    [self.deleteGrowpBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).with.offset(-30*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(80*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.lineView = [[UIView alloc]init];
    self.lineView.backgroundColor =UIColorFromRGB(241, 241, 241);
    [self.contentView addSubview:self.lineView];
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).with.offset(50*AutoScaleVertical);
        make.width.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1*AutoScaleVertical);
    }];
    
    switch (section+1) {
        case 1:
            self.titleLabel.text = @"添加第一组测试项目";
            break;
        case 2:
            self.titleLabel.text = @"添加第二组测试项目";
            break;
        case 3:
            self.titleLabel.text = @"添加第三组测试项目";
            break;
        case 4:
            self.titleLabel.text = @"添加第四组测试项目";
            break;
        case 5:
            self.titleLabel.text = @"添加第五组测试项目";
            break;
        case 6:
            self.titleLabel.text = @"添加第六组测试项目";
            break;
        case 7:
            self.titleLabel.text = @"添加第七组测试项目";
            break;
        case 8:
            self.titleLabel.text = @"添加第八组测试项目";
            break;
        default:
            break;
    }
    //创建项目
    for (int a = 0; a< array.count+1; a++) {
        if (a<array.count) {
            NSMutableDictionary * dic = array[a];
            //带文字和图片的按钮
            UIButton * probtn = [UIButton buttonWithType:UIButtonTypeCustom];
            probtn.selected = NO;
            probtn.tag = a + 200;
            [probtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"project-%@",[dic objectForKey:@"proNum"]]] forState:UIControlStateNormal];
            [probtn setTitle:[dic objectForKey:@"proName"] forState:UIControlStateNormal];
            [probtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            probtn.titleLabel.font = [UIFont systemFontOfSize:12*AutoScaleHorizontal];
            //设置按钮图片在上文字在下
            probtn.imageEdgeInsets = UIEdgeInsetsMake(-30*AutoScaleVertical, 0, 0, 0);
            probtn.titleEdgeInsets = UIEdgeInsetsMake(50*AutoScaleVertical, -60*AutoScaleHorizontal, 0, 0);
            //        [probtn addTarget:self action:@selector(pressPro:) forControlEvents:UIControlEventTouchUpInside];
            [self.contentView addSubview:probtn];
            [probtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.contentView.mas_left).with.offset((60+130*(a%4))*AutoScaleHorizontal);
                make.top.mas_equalTo(self.contentView.mas_top).with.offset((90+130*(a/4)*AutoScaleVertical));
                make.size.mas_equalTo(CGSizeMake(65*AutoScaleHorizontal, 90*AutoScaleVertical));
                if (a==7) {
                    make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_offset(-20);
                }
            }];
            //IMAGEVIEW 小对勾 标记按钮状态a
            UIButton * deleBTN = [UIButton buttonWithType:UIButtonTypeCustom];
            [deleBTN setImage:[UIImage imageNamed:@"deletePro"] forState:UIControlStateNormal];
            deleBTN.tag = a + 200;
            [deleBTN addTarget:self action:@selector(deleteSmall:) forControlEvents:UIControlEventTouchUpInside];
            [probtn addSubview: deleBTN];
            [deleBTN mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(probtn.mas_top).with.offset(-15*AutoScaleVertical);
                make.right.mas_equalTo(probtn.mas_right).with.offset(-1*AutoScaleHorizontal);
                make.size.mas_equalTo(CGSizeMake(40*AutoScaleHorizontal, 40*AutoScaleVertical));
            }];
        }else if (a != 8){
            UIButton * addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [addBtn setImage:[UIImage imageNamed:@"addPro"] forState:UIControlStateNormal];
            [addBtn addTarget:self action:@selector(showViewAction) forControlEvents:UIControlEventTouchUpInside];
            [self.contentView addSubview:addBtn];
            [addBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.contentView.mas_left).with.offset((60+130*(a%4))*AutoScaleHorizontal);
                make.top.mas_equalTo(self.contentView.mas_top).with.offset((75+130*(a/4)*AutoScaleVertical));
                make.size.mas_equalTo(CGSizeMake(65*AutoScaleHorizontal, 90*AutoScaleVertical));
                make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_offset(-20);
            }];
        }
    }
}
//添加
- (void)showViewAction{
    NSLog(@"1");
    self.callAction();
}
//删除组
-(void)godelete{
    NSLog(@"2");
    self.callDelete();
}
//删除小项目
-(void)deleteSmall:(UIButton*)sender{
    self.callDeleteSmall(sender.tag-200);
}

#pragma mark 重写setFrame方法，自己调整cell的frame
- (void)setFrame:(CGRect)frame
{
    // 更改x、宽度
    frame.origin.x = SCREEN_WIDTH/5;
    frame.size.width = SCREEN_WIDTH/5 * 3;
    
//    // 更改顶部间距、每个cell之间的间距
//    frame.origin.y += kTableTopBorderWidth;
//    frame.size.height -= kTableViewCellMargin;
//    
    [super setFrame:frame];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
